<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
    <style>
        .div1{
            border: black 1px;
            position: fixed;
        }
    </style>
<body>
    <div class="div1">w</div>
    <script>
        var div=document.querySelector('div');
        document.onkeydown = function(event){
            console.log(event);
            switch(event.keyCode){
                case 37:
                    div.style.left = div.offsetLeft-1+'px';
                    break;
                case 39:
                    div.style.left=div.offsetLeft+1+'px';
                    break;
                case 40:
                    div.style.top = div.offsetTop+1+'px';
                    break;
                case 38:
                    div.style.top = div.offsetTop-1+'px';
                    break;
            }   
        }
    </script>
</body>
</html>